package edu.cmu.fithub.formbeans;

import java.util.ArrayList;
import java.util.List;
import java.util.TimeZone;

import org.mybeans.form.FormBean;

public class LoginForm extends FormBean {

	private String username;
	private String password;
	private String action;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public List<String> getValidationErrors() {
		List<String> errors = new ArrayList<String>();

		if (username == null || username.length() == 0) {
			errors.add("UserName is required");
		} else if (username.matches(".*[<>].*")) {
			errors.add("Username may not contain angle brackets");
			username = username.replaceAll(">", "&gt;");
			username = username.replaceAll("<", "&lt;");
			username = username.replaceAll(" ", "&nbsp;");
		}

		if (password == null || password.length() == 0) {
			errors.add("Password is required");
		} else if (password.matches(".*[<>].*")) {
			errors.add("Password may not contain angle brackets");
			password = "";
		}

		return errors;
	}
}
